<?php

namespace Admin\Models\Components;

use Hirudo\Models\Components\Sql\SimpleSqlComponent;

/**
 * Description of MediaComponent
 *
 * @author Elkin José
 */
class MediaComponent extends SimpleSqlComponent {
    public function getAll() {
        return $this->getQuery()
                        ->select()
                        ->from(array("dusb_media"))
                        ->get()
                        ->resultList();
    }
    
    public function getByPlugin($idPlugin) {
        return $this->getQuery()
                ->select()
                ->from(array("dusb_media"))
                ->where("id_plugin", $idPlugin)
                ->get()
                ->resultList();
    }
    
    public function getById($idMedia) {
        return $this->getQuery()
                ->select()
                ->from(array("dusb_media"))
                ->where("id", $idMedia)
                ->get()
                ->resultList();
    }
    
    public function delete($idMedia) {
        return $this->getQuery()
                ->delete("dusb_media")
                ->where("id", $idMedia)
                ->commit();
    }

    public function add($fileInfo) {
        $this->getQuery()->insertInto("dusb_media")
                ->set("id_plugin", $fileInfo['idPlugin'])
                ->set("name", $fileInfo['name'])
                ->set("format", $fileInfo['format'])
                ->set("title", $fileInfo['title'])
                ->set("second_title", $fileInfo['secondTitle'])
                ->commit();
    }
}

?>